<%--
  Created by IntelliJ IDEA.
  User: yun
  Date: 2024/6/23
  Time: 14:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>学生管理系统</title>
    <script src="../js/jquery-1.11.3.js"></script>
    <style>
        .stuList{
            width: 100%;
        }
        h1{
            text-align: center;
        }
        tr{
            text-align: center;
        }
    </style>
</head>
<body>
<div class="stuList">
    <h1 style="text-align: center">学生信息列表</h1>
    <table border="1" cellspacing="0">
        <thead>
        <tr title="center">
            <td>学员编号</td>
            <td>学员姓名</td>
            <td>学员性别</td>
            <td>学员年龄</td>
            <td>家庭地址</td>
            <td>Email</td>
            <td>操作</td>
        </tr>
        </thead>
    </table>
</div>
</body>
</html>
<script>
    $.ajax({
        url:'${pageContext.request.contextPath}/student.action',
        type:'get',
        data:{opr:'list'},
        dataType:'json',
        success:stuList,
        error:function () {
            alert("查询失败")
        }
    })

    function stuList(data) {
        console.log(data)
        data.forEach(dd=>{
            let tr =$(`<tr>
                            <td>`+dd.id+`</td>
                            <td>`+dd.sname+`</td>
                            <td>`+dd.sgender+`</td>
                            <td>`+dd.sage+`</td>
                            <td>`+dd.saddress+`</td>
                               <td>`+dd.semail+`</td>
                            <td>
                                <button onclick="del(`+dd.id+`)">删除</button>
                                <button onclick="updata(`+dd.id+`)">更新</button>
                            </td>
                       </tr>
             `)
            $('tbody').append(tr);
        })
    }

    function del(id) {
        window.location.href="/student.action?opr=del&&id="+id;
    }

    function updata(id) {
        window.location.href="/student.action?opr=updata&&id="+id;
    }
</script>
